#ifndef ModbusMasterProxy_H
#define ModbusMasterProxy_H

#include <QObject>
#include "modbus.h"
#include "modbus-private.h"
#include "modbus-rtu.h"
#include "modbus-tcp.h"

class ModbusMasterProxy : public QObject
{
    Q_OBJECT
public:
    explicit ModbusMasterProxy(QObject *parent = nullptr);
    ~ModbusMasterProxy();
    void clearCount();
    uint32_t respCount();
    uint32_t pollCount();
    void setProxy(modbus_t** ctx);
    bool isConnected(void);
    bool isBusy(void);
private:
    modbus_t** ctx;
    uint32_t _respCount, _pollCount;
    bool _isBusy;
signals:
    void response(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToReadWirte, QByteArray data);
public slots:
    void read(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToRead,  quint32 responseTimeout);
    void write(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToWrite, QByteArray data, quint32 responseTimeout);
};

#endif // ModbusMasterProxy_H
